package com.awesumgames.awesum;

import com.awesumgames.awesum.Vector3;
import com.awesumgames.awesum.AwesumGlobal.Awesum;
import com.awesumgames.awesum.sprites.Sprite;
import com.bulletphysics.collision.shapes.BoxShape;
import com.bulletphysics.collision.shapes.SphereShape;

public final class Primitives {
	public static void buildRect(Drawable d, Vector3 dims, Vector4 color, short maskType, short maskCollidesWith) {
		if (d.gl == null) {
			Awesum.debug("Primitives.buildRect: Drawable does not have a GL trait!");
			return;
		}
		float vertices[] = new float[] {
			-dims.x,-dims.y,dims.z,		dims.x,-dims.y,	dims.z,		dims.x,	dims.y,	dims.z,		-dims.x,dims.y,dims.z,		//front
			-dims.x,-dims.y,-dims.z,	-dims.x,dims.y,-dims.z,		dims.x,	dims.y,	-dims.z,	dims.x,-dims.y,	-dims.z,	//back
			-dims.x,-dims.y,dims.z,		-dims.x,-dims.y,-dims.z,	dims.x,	-dims.y,-dims.z,	dims.x,-dims.y,	dims.z,		//top
			-dims.x,dims.y,-dims.z,		-dims.x,dims.y,dims.z,		dims.x,	dims.y,dims.z,		dims.x,	dims.y,-dims.z,		//bottom
			dims.x,-dims.y,-dims.z,		dims.x,dims.y,	-dims.z,	dims.x,dims.y,	dims.z,		dims.x,-dims.y,dims.z,		//left
			-dims.x,-dims.y,dims.z,		-dims.x,dims.y,dims.z,		-dims.x,dims.y,	-dims.z,	-dims.x,-dims.y,-dims.z		//right
		};
		float normals[] = new float[] {
			0f, 0f, 1f,		0f, 0f, 1f,		0f, 0f, 1f,		0f, 0f, 1f,		//front
			0f, 0f, -1f,	0f, 0f, -1f,	0f, 0f, -1f,	0f, 0f, -1f,	//back
			0f, 1f, 0f,		0f, 1f, 0f,		0f, 1f, 0f,		0f, 1f, 0f,		//top
			0f, -1f, 0f,	0f, -1f, 0f,	0f, -1f, 0f,	0f, -1f, 0f,	//bottom
			-1f, 0f, 0f,	-1f, 0f, 0f,	-1f, 0f, 0f,	-1f, 0f, 0f,	//left
			1f, 0f, 0f,		1f, 0f, 0f,		1f, 0f, 0f,		1f, 0f, 0f		//right
		};
		short indices[] = new short[] {
			0, 1, 2,	2, 3, 0,	//front
			4, 5, 6,	6, 7, 4,	//back
			8, 9, 10,	10, 11, 8,	//top
			12, 13, 14,	14, 15, 12,	//bottom
			16, 17, 18,	18, 19, 16,	//left
			20, 21, 22,	22, 23, 20	//right
		};
		d.gl.model.vertices = Awesum.makeFloatBuffer(vertices);
		d.gl.model.normals = Awesum.makeFloatBuffer(normals);
		d.gl.model.indices = Awesum.makeShortBuffer(indices);
		d.gl.model.color.set(color);
		d.gl.setDrawModeTriangles();
		d.gl.load();
	}
	
	public static void buildSphere(Drawable d, float radius, float mass, float restitution, short maskType, short maskCollidesWith) {//, float... args) {
		if (d.phys != null) {
			d.phys.collShape = new SphereShape(radius);
			d.phys.init(mass, restitution, maskType, maskCollidesWith);
		}
	}
	
	
	/*public static void buildSquare(Sprite s, Vector3 dims) {
		float vertices[] = new float[] {
			0f,		0f,		0f,		0f, 1f,
			dims.x,	0f,		0f,		1f, 1f,
			dims.x,	dims.y,	0f,		1f, 0f,
			0f,		dims.y,	0f,		0f, 0f
		};
		short indices[] = new short[] {
			0, 1, 2,	2, 3, 0
		};
		s.model.vertices = Awesum.makeFloatBuffer(vertices);
		s.model.indices = Awesum.makeShortBuffer(indices);
		s.model.drawMode = GLES20.GL_TRIANGLES;
	}*/
}
